package gamedemo.day09game.game01;

import java.util.Random;

public class Role {
    // 姓名
    private String name;
    private int ph;
    private String face;
    private String gender;
    String[] boyfaces= {"风流俊雅","气宇轩昂","相貌英俊","五官端正","相貌平平","一塌糊涂","面目狰狞"};
    String[] girlfaces ={"美奂绝伦","沉鱼落雁","婷婷玉立","身材娇好","相貌平平","相貌简陋","惨不忍睹"};

    String[] attacks_desc={
    "%s使出了一招【背心钉】，转到对方的身后，一掌向%s背心的灵台穴拍去。",
    "%s使出了一招【游空探爪】，飞起身形自半空中变掌为抓锁向%s。",
    "%s大喝一声，身形下伏，一招【劈雷坠地】，捶向%s双腿。",
    "%s运气于掌，一瞬间掌心变得血红，一式【掌心雷】，推向%s。",
    "%s阴手翻起阳手跟进，一招【没遮拦】，结结实实的捶向%s。",
    "%s上步抢身，招中套招，一招【劈挂连环】，连环攻向%s。"
    };

    String[] injureds_desc={
    "结果%s退了半步，毫发无损",
    "结果给%s造成一处瘀伤",
    "结果一击命中，%s痛得弯下腰",
    "结果%s痛苦地闷哼了一声，显然受了点内伤",
    "结果%s摇摇晃晃，一跤摔倒在地",
    "结果%s脸色一下变得惨白，连退了好几步",
    "结果『轰』的一声，%s口中鲜血狂喷而出",
    "结果%s一声惨叫，像滩软泥般塌了下去"
    };
    
    public Random r = new Random();
    public Role(String name, int ph, String gender) {
        // 性别为女则在女生的面部描述中获取买面部
        if ("女".equals(gender)){
            int index = r.nextInt(girlfaces.length);
            this.face = girlfaces[index];
            
        }else if("男".equals(gender)){
            // 性别为男所获取的面部描述
            int index = r.nextInt(boyfaces.length);
            this.face = boyfaces[index];
        }else{
            // 未知性别则面目狰狞
            this.face = boyfaces[boyfaces.length-1];
        }
        this.name = name;
        this.ph = ph;
        this.gender = gender;
    }
    // 展示角色所有信息
    public void show(){
        System.out.println(this.name+"性别是："+this.gender+this.face+"血量是"+this.ph);
    }
    // 攻击方法
    public void attack(Role rl){
        
        // 获取攻击值
        int hurt_num = r.nextInt(21);
        // 根据攻击值对应输出攻击语句
        if (hurt_num <= 4){
            System.out.printf(attacks_desc[0],this.name,rl.getName());
        }else if(hurt_num <= 8){
            System.out.printf(attacks_desc[1],this.name,rl.getName());
        }else if(hurt_num <= 13){
            System.out.printf(attacks_desc[2],this.name,rl.getName());
        }else if(hurt_num <=16){
            System.out.printf(attacks_desc[3],this.name,rl.getName());
        }else if(hurt_num <= 18){
            System.out.printf(attacks_desc[4],this.name,rl.getName());
        }else{
            System.out.printf(attacks_desc[5],this.name,rl.getName());
        }
        System.out.println();
        // 根据伤害输出受伤角色受伤语句
        rl.injured(hurt_num);
        
    }
    // 受伤方法
    public void injured(int hurt_num){
        if (hurt_num == 0){
            System.out.printf(injureds_desc[0],this.name);
        }else if(hurt_num <= 5){
            System.out.printf(injureds_desc[1],this.name);
        }else if(hurt_num <= 8){
            System.out.printf(injureds_desc[2],this.name);
        }else if(hurt_num <=12){
            System.out.printf(injureds_desc[3],this.name);
        }else if(hurt_num <= 15){
            System.out.printf(injureds_desc[4],this.name);
        }else if(hurt_num <= 17){
            System.out.printf(injureds_desc[5],this.name);
        }else if(hurt_num <= 20){
            System.out.printf(injureds_desc[6],this.name);
        }
        System.out.println();
        // 计算受伤角色的血量
        this.ph -= hurt_num;
        if (this.ph <= 0){
            System.out.printf(injureds_desc[7],this.name);
        }
    }
    public Role() {
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getPh() {
        return ph;
    }
    public void setPh(int ph) {
        this.ph = ph;
    }
    
}
